package com.jungle.client;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;

public class FxApplication extends Application {

    public static final ResourceBundle bundle = ResourceBundle.getBundle("messages", Locale.getDefault());

    @Override
    public void start(Stage stage) throws IOException {
        desktopView(stage);
    }

    private static void loginView(Stage stage) throws IOException {
        FXMLLoader loader = new FXMLLoader(FxApplication.class.getResource("login-view.fxml"));
        loader.setResources(bundle);
        Scene scene = new Scene(loader.load(), 320, 240);
        stage.setTitle(bundle.getString("login.title"));
        stage.setScene(scene);
        stage.show();
    }

    private static void desktopView(Stage stage) throws IOException {
        FXMLLoader loader = new FXMLLoader(FxApplication.class.getResource("main.fxml"));
        // 设置资源
        loader.setResources(bundle);
        // 构建场景
        Scene scene = new Scene(loader.load(), 900, 600);
        // 加载样式表
        URL styleUrl = FxApplication.class.getResource("/styles/style.css");
        if (styleUrl != null) {
            scene.getStylesheets().add(styleUrl.toExternalForm());
        }
        // 设置应用标题
        stage.setTitle(bundle.getString("app.title"));
        // 设置应用图标
        URL iconUrl = FxApplication.class.getResource("/images/icon.png");
        if (iconUrl != null) {
            stage.getIcons().add(new javafx.scene.image.Image(iconUrl.toExternalForm()));
        }
        // 设置应用场景
        stage.setScene(scene);
        // 显示应用
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}